{extend name="base/form_base" /}
{block name="content"}
        <form class="layui-form" id="edit_form" onsubmit="return false">
          <input type="hidden" value="{$data.id ?? ''}" name="id" />
          <div class="layui-form-item">
            <label class="layui-form-label">程序名</label>
            <div class="layui-input-block">
              <input name="name" required="" lay-verify="required" autocomplete="off" class="layui-input" type="text" value="{$data.name ?? ''}">
            </div>
            <div class="layui-form-mid layui-word-aux"></div> 
          </div>
          <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">简介</label>
          <div class="layui-input-block">
            <textarea name="ms" placeholder="请输入内容" class="layui-textarea">{$data.ms ?? ''}</textarea>
          </div>
        </div>
          <div class="layui-form-item">
            <label class="layui-form-label">图标：</label>
            <div class="layui-input-inline">
                <img src="{$data.pic ?? ''}" style="width: 100px;height: 100px" id="show_upload_img">
                <input type="hidden" name="pic" id='pic' value="{$data.pic ?? ''}">
             </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon"></i>上传图片
              </button>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
              <input name="url" lay-vertype="tips" placeholder="链接地址" autocomplete="off" class="layui-input" type="text"  value="{$data.url ?? ''}">
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">是否开放</label>
              <div class="layui-input-block">
                {if $data.status == 1}
                  <input type="radio" name="status" value="1" title="开放" checked="">
                  <input type="radio" name="status" value="0" title="不开放">
                {else /}
                  <input type="radio" name="status" value="1" title="开放">
                  <input type="radio" name="status" value="0" title="不开放" checked="">
                {/if}
              </div>
            </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-filter="formDemo" onclick="ajax()">立即提交</button>
            </div>
          </div>
        </form>
{/block}
{block name="script"}
<script>
      layui.use('upload', function(){
      var upload = layui.upload;
      upload.render({
      elem: '#upload'
      ,url: '{:C("system_url")}/api/Upload/upload_img'
      ,before:function(){
        var index = layer.msg('正在拼命处理...' , {
          icon: 16 ,
          shade: 0.6 ,
          time: 0 ,
        });
      }
      ,done: function(res){
        if(res.code==0){
          $("#show_upload_img").attr('src',res.data);
           $("#pic").val(res.data);
          layer.msg('上传图片成功');
        } else {
          layer.msg('上传图片失败');
        }
      }
      });      
    });
    function ajax(){
      var post_data = $("#edit_form").serialize();
      $.ajax({
          url:"{:url('admin/community/editApp')}",
          type:"POST",
          data:post_data,
          success:function(ret){
              if (ret.code == 0) {
                layer.msg('修改成功');
                window.location.reload();
                parent.$(".layui-laypage-btn")[0].click();
              }
              if (ret.code == 1) {
                  layer.msg(ret.msg);
              }
          }
      });
    }
</script>
{/block}
